//
// Created by Semir on 2020/6/5.
//

#include <iostream>
#include <string>
#include <vector>

using namespace std;


//TODO 撒打发
struct ListNode {
    int val;
    struct ListNode *next;
    explicit ListNode(int x) : val(x), next(nullptr) {}
};

ListNode* FindFirstCommonNode(ListNode* pHead1, ListNode* pHead2) {
    if (pHead1 == nullptr || pHead2 == nullptr) {
        return nullptr;
    }
    ListNode* ptr1 = pHead1;
    ListNode* ptr2 = pHead2;
    while (ptr1->next != nullptr && ptr2->next != nullptr) {
        ptr1 = ptr1->next;
        ptr2 = ptr2->next;
    }
    if (ptr1->next == nullptr) {
        ptr1 = pHead2;
    } else {
        ptr2 = pHead1;
    }
    while (ptr1->next != nullptr && ptr2->next != nullptr) {
        ptr1 = ptr1->next;
        ptr2 = ptr2->next;
    }
    if (ptr1->next == nullptr) {
        ptr1 = pHead2;
    } else {
        ptr2 = pHead1;
    }
    while (ptr1 != ptr2) {
        ptr1 = ptr1->next;
        ptr2 = ptr2->next;
    }
    return ptr1;
}

int main() {

    return 0;
}